home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / processes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-05  |  1.4 KB  |  62 lines

  1. #include "amiga.h"
  2. #include <clib/alib_protos.h>
  3.  
  4. #include "processes.h"
  5.  
  6. int _next_pid, _our_pid;
  7. struct MinList _processes;
  8. char _door_name[DOOR_LEN];
  9. struct MsgPort *_children_exit;
  10. struct MsgPort *_startup_port;
  11.  
  12. int _sprintf(char *, const char *,...);
  13. void _fail(char *format,...);
  14.  
  15. void _free_entry(struct process *p)
  16. {
  17.     Remove((struct Node *) p);
  18.     free(p);
  19. }
  20.  
  21. struct process *_find_pid(int pid)
  22. {
  23.     struct process *entry;
  24.  
  25.     scan_processes(entry) if (entry->pid == pid)
  26.     return entry;
  27.  
  28.     return 0;
  29. }
  30.  
  31. void _init_processes(void)
  32. {
  33.     NewList((struct List *) &_processes);
  34.     /* Choose a fairly unique pid for ourselves, but keep it within a range
  35.        which guarantees positive pid's for all created processes.
  36.        This range is further restricted to 23 bits so that a pid fits within the
  37.        range of an emacs number (generally 24 bits, though it is 26 on the Amiga) */
  38.     _our_pid = ((int) _us ^ _startup_time) & 0x7fffff;
  39.     _next_pid = _our_pid + 1;
  40.     _sprintf(_door_name, "door.%lx.%lx", _us, _startup_time);
  41.     if ((_startup_port = CreateMsgPort()) &&
  42.     (_children_exit = CreatePort(_door_name, 0)))
  43.     return;
  44.  
  45.     _fail("No memory");
  46. }
  47.  
  48. void _cleanup_processes(void)
  49. {
  50.     if (_startup_port)
  51.     DeleteMsgPort(_startup_port);
  52.     if (_children_exit) {
  53.     struct exit_message *msg;
  54.  
  55.     Forbid();
  56.     while (msg = (struct exit_message *) GetMsg(_children_exit))
  57.         FreeMem(msg, sizeof(struct exit_message));
  58.     DeletePort(_children_exit);
  59.     Permit();
  60.     }
  61. }
  62.